<template>
    <div class="menu-demo">
        <a-menu mode="horizontal" @menu-item-click="handleItemClick()" :default-selected-keys="['1']">
            <a-menu-item :disabled="true">GdpuBBS</a-menu-item>
            <a-menu-item key="1"><icon-home />首页</a-menu-item>

            <!-- <a-input-search :style="{ width: '320px' }" placeholder="输入搜索的帖子" search-button /> -->

            <!-- <a-menu-item key="2">2</a-menu-item> -->
            <!-- 主题亮暗开关 -->
            <a-button style="float: right;" @click="changeTheme"> {{ themName }}</a-button>

            <!-- 头像 -->
            <a-dropdown @select="handleSelect">
                <a-avatar style="float: right; margin-right: 20px;">
                    <img alt="avatar" :src="$store.state.user.picture" />
                </a-avatar>
                <template #content>
                    <a-doption v-if="!$store.state.user.is_login" @click=" gotologin()"><icon-import />立即登录</a-doption>
                    <a-doption v-if="$store.state.user.is_login" @click="gotologout()"><icon-import />退出登录</a-doption>
                </template>
            </a-dropdown>


        </a-menu>
    </div>
</template>

<script>
import { ref } from 'vue';
import { IconImport, IconHome } from '@arco-design/web-vue/es/icon';
import router from '@/router'
import { Message } from '@arco-design/web-vue';
import store from '@/store';

export default {
    components: {
        IconImport, IconHome
    },
    methods: {
        gotologin() {
            router.push({ name: "UserLoginView" })
        },
        gotologout() {
            Message.info({ content: "退出登录" })
            localStorage.removeItem('user');
            store.commit('ResetState');
        }
    },
    setup() {
        let isdark = ref(''), themName = ref('');
        isdark.value = false; themName.value = '暗色模式';
        document.body.setAttribute('arco-theme', 'light')

        const changeTheme = () => {
            if (isdark.value === false) {
                document.body.setAttribute('arco-theme', 'dark')
                isdark.value = true;
            } else {
                // 亮色模式
                document.body.removeAttribute('arco-theme');
                isdark.value = false;
                themName.value = '暗色模式';
            }
        }

        const handleItemClick = () => {
            console.log("click Menu");
            router.push('/post/index')
        }

        return {
            isdark, themName,
            changeTheme, handleItemClick
        }
    }
}
</script>
<style scoped>
.menu-demo {
    box-sizing: border-box;
    width: 100%;
    background-color: var(--color-neutral-2);
}
</style>
  